﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegetAndEventTest.PbulishAndSubscribe
{
    /// <summary>
    /// 订阅者
    /// </summary>
    class Subscribe : ISubscribe
    {
        public int Id { get; set; }
        public string Name { get; set; }
        private bool IsSubject { get; set; }
        private Dispatch dispatch { get; set; }
        public Subscribe(Dispatch dispatch)
        {
            this.dispatch = dispatch;
        }
        /// <summary>
        /// 显示消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ReciveMessage(object sender, WeatherEventArgs e)
        {
            var message = $"尊敬的{Name}客户您好，您尚未订阅我们的产品，无法观看当前天气";
            if (IsSubject)
            {
                message = $"尊敬的{Name}先生女士您好,{e.Message}";
            }
            Console.WriteLine(message);
            
        }

        /// <summary>
        /// 订阅消息
        /// </summary>
        public void Subscribtion()
        {
            IsSubject = true;
            dispatch.WeatherReport += ReciveMessage;
        }

        /// <summary>
        /// 取消订阅
        /// </summary>
        public void CancelMessage()
        {
            IsSubject = false;
        }
    }
}
